package com.jiang.daily.Q2929;

/**
 * @author Jiang
 * @version 1.0
 * @date 2025/06/01 1:11
 */
class Solution {
    public long distributeCandies(int n, int limit) {
        long res = 0;
        for (int i = 0; i <= Math.min(n, limit); i++) {
            if (n - i > 2 * limit) {
                continue;
            }
            res += Math.min(n - i, limit) - Math.max(0, n - i - limit) + 1;
        }
        return res;
    }
}
